//
//  LGFollowDataSymptomHeader.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/21.
//

#import "LGFollowDataGlucoseHeader.h"


#define dateWidth   viewPix(45)
#define itemWidth   (Screen_W-viewPix(56)-dateWidth)/7.0

@interface LGFollowDataGlucoseHeader()
/**   */
@property (nonatomic , strong)UIView *shadowView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIView *segmentView;
/**   */
@property (nonatomic , strong)UIView *baseView;

@end

@implementation LGFollowDataGlucoseHeader

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.clipsToBounds = YES;
        self.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
        [self addSubview:self.shadowView];
        [self.shadowView addSubview:self.iconView];
        [self.shadowView addSubview:self.titleLabel];
        [self.shadowView addSubview:self.segmentView];
        [self.shadowView addSubview:self.baseView];
        [self.shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(viewPix(5));
            make.left.equalTo(self).offset(viewPix(16));
            make.right.equalTo(self).offset(-viewPix(16));
            make.bottom.equalTo(self).offset(viewPix(15));
        }];
        [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(self.shadowView).offset(viewPix(12));
            make.width.height.equalTo(@(viewPix(24)));
        }];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconView.mas_right).offset(viewPix(6));
            make.centerY.equalTo(self.iconView);
        }];
        [self.segmentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.shadowView).offset(viewPix(48));
            make.left.equalTo(self.shadowView).offset(viewPix(12));
            make.right.equalTo(self.shadowView).offset(-viewPix(12));
            make.height.equalTo(@(0.5));
        }];
        [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.segmentView.mas_bottom).offset(viewPix(12));
            make.left.right.equalTo(self.segmentView);
            make.bottom.equalTo(self.shadowView);
        }];
        [self createLineView];
    }
    return self;
}


-(UIView *)shadowView{
    if(!_shadowView){
        _shadowView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:10];
        _shadowView.backgroundColor = [UIColor whiteColor];
    }
    return _shadowView;
}
-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"添加随访-血糖"]];
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"血糖" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UIView *)segmentView{
    if(!_segmentView){
        _segmentView = [[UIView alloc]initWithFrame:CGRectMake(viewPix(12), viewPix(48), Screen_W-viewPix(56), 0.5)];
        _segmentView.backgroundColor = [UIColor colorWithString:@"#E8E8E8"];
    }
    return _segmentView;
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.layer.borderColor = [UIColor colorWithString:@"#E0E0E0"].CGColor;
        _baseView.layer.borderWidth = 1;
        _baseView.cornerRidus = 7;
    }
    return _baseView;
}

-(void)createLineView{
    NSArray *dinnerArray = @[@"早餐",@"午餐",@"晚餐"];
    NSArray *itemArray = @[@"空腹",@"后",@"前",@"后",@"前",@"后",@"睡前"];
    for (NSInteger i=0; i<7; i++) {
        CGFloat top = (i%2==1)?viewPix(20):0;
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(dateWidth+itemWidth*i, top, 1, viewPix(40)-top)];
        lineView.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
        [self.baseView addSubview:lineView];
        
        CGFloat itemTop = (i==itemArray.count-1)?0:viewPix(20);
        
        UILabel *itemLabel = [UILabel lableWithText:itemArray[i] colorString:@"#333333" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
        itemLabel.frame = CGRectMake(dateWidth+itemWidth*i, itemTop, itemWidth-1, viewPix(40)-itemTop);
        [self.baseView addSubview:itemLabel];
        
        if(i%2==0 && i/2<dinnerArray.count){
            UILabel *dinnerLabel = [UILabel lableWithText:dinnerArray[i/2] colorString:@"#333333" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
            dinnerLabel.frame = CGRectMake(dateWidth+itemWidth*i, 0, itemWidth*2-1, viewPix(20));
            [self.baseView addSubview:dinnerLabel];
        }
    }
    
    UILabel *sleepLabel = [UILabel lableWithText:@"日期" colorString:@"#333333" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    sleepLabel.frame = CGRectMake(0, 0, dateWidth, viewPix(40));
    [self.baseView addSubview:sleepLabel];
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(dateWidth, viewPix(20), itemWidth*6, 1)];
    lineView.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    [self.baseView addSubview:lineView];
}

@end
